package com.ljx.funchat.user.controller;


import com.ljx.funchat.common.domain.vo.req.CursorPageBaseReq;
import com.ljx.funchat.common.domain.vo.resp.ApiResult;
import com.ljx.funchat.common.domain.vo.resp.CursorPageBaseResp;
import com.ljx.funchat.common.utils.RequestHolder;
import com.ljx.funchat.user.domain.vo.req.UserFriendApplyReq;
import com.ljx.funchat.user.domain.vo.req.UserFriendDeleteReq;
import com.ljx.funchat.user.domain.vo.req.UserFriendHandleReq;
import com.ljx.funchat.user.domain.vo.req.UserFriendSearchReq;
import com.ljx.funchat.user.domain.vo.resp.UserApplyResp;
import com.ljx.funchat.user.domain.vo.resp.UserFriendResp;
import com.ljx.funchat.user.domain.vo.resp.UserFriendSearchResp;
import com.ljx.funchat.user.domain.vo.resp.UserResp;
import com.ljx.funchat.user.service.IUserFriendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.validation.Valid;

/**
 * <p>
 * 好友表 前端控制器
 * </p>
 *
 * @author LiJunXi
 * @since 2024-02-14
 */
@Api(tags = "联系人接口")
@RestController
@RequestMapping("/user/friend")
public class UserFriendController {

   @Autowired
    private IUserFriendService userFriendService;

    @ApiOperation("联系人列表")
    @GetMapping("/page")
    public ApiResult<CursorPageBaseResp<UserFriendResp>> friendPage(@Valid CursorPageBaseReq request){
        Long uid = RequestHolder.get().getUid();

        return ApiResult.success(userFriendService.friendPage(uid, request));
    }

    @ApiOperation("搜索好友/群聊")
    @PostMapping("/search")
    public ApiResult<UserFriendSearchResp> search(@Valid @RequestBody UserFriendSearchReq req){
        Long uid = RequestHolder.get().getUid();

        return ApiResult.success(userFriendService.search(uid, req));
    }

    @ApiOperation("删除好友")
    @PutMapping("/delete")
    public ApiResult<Void> deleteFriend(@Valid @RequestBody UserFriendDeleteReq req){
        Long uid = RequestHolder.get().getUid();
        userFriendService.deleteFriend(uid, req);

        return ApiResult.success();
    }
}

